<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>股票价格预测结果 - Flask应用</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <style>
        .chart-container {
            position: relative;
            margin: auto;
            height: 500px;
            width: 100%;
        }
        .price-up {
            color: #10b981;
        }
        .price-down {
            color: #ef4444;
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <header class="bg-stock text-white shadow-md">
        <div class="container mx-auto px-4 py-6">
            <h1 class="text-3xl font-bold text-center">股票价格预测结果</h1>
            <p class="text-center mt-2">股票代码: {{ code }}</p>
        </div>
    </header>

    <div class="container mx-auto px-4 py-8">
        <div class="max-w-6xl mx-auto">
            <!-- 股票基本信息卡片 -->
            <div class="bg-white rounded-lg shadow-lg p-6 mb-8">
                <div class="flex flex-col md:flex-row justify-between items-start md:items-center">
                    <div>
                        <h2 class="text-2xl font-bold text-gray-800 mb-1">股票代码: {{ code }}</h2>
                        <p class="text-gray-600">最后更新价格: <span class="text-xl font-semibold">{{ last_price }}</span></p>
                    </div>
                    <a href="/prestock/" class="mt-4 md:mt-0 bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-4 rounded transition-colors duration-300">
                        返回首页
                    </a>
                </div>
            </div>

            <!-- 预测图表 -->
            <div class="bg-white rounded-lg shadow-lg p-6 mb-8">
                <h3 class="text-xl font-bold text-gray-800 mb-4">股票价格预测图表</h3>
                <div class="chart-container">
                    <img src="data:image/png;base64,{{ chart_image }}" alt="股票价格预测图表" class="w-full h-full object-contain">
                </div>
            </div>

            <!-- 预测结果表格 -->
            <div class="bg-white rounded-lg shadow-lg p-6">
                <h3 class="text-xl font-bold text-gray-800 mb-4">未来5个交易日价格预测</h3>
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    日期
                                </th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    预测价格
                                </th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    与前一日对比
                                </th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            {% for result in results %}
                            <tr>
                                <!-- result.html中的价格对比部分 -->
                                <td class="px-6 py-4 whitespace-nowrap text-sm">
                                    {% if loop.first %}
                                        <!-- 首行对比最后一个实际价格 -->
                                        {% if result.price > last_price %}
                                            <span class="price-up">+{{ (result.price - last_price)|round(2) }}</span>
                                        {% elif result.price < last_price %}
                                            <span class="price-down">-{{ (last_price - result.price)|round(2) }}</span>
                                        {% else %}
                                            <span class="text-gray-500">持平</span>
                                        {% endif %}
                                    {% else %}
                                        <!-- 后续行对比前一天预测价格 -->
                                        {% set prev_price = results[loop.index0-1].price %}
                                        {% if result.price > prev_price %}
                                            <span class="price-up">+{{ (result.price - prev_price)|round(2) }}</span>
                                        {% elif result.price < prev_price %}
                                            <span class="price-down">-{{ (prev_price - result.price)|round(2) }}</span>
                                        {% else %}
                                            <span class="text-gray-500">持平</span>
                                        {% endif %}
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="mt-4 text-sm text-gray-500">
                    <p>注：预测结果基于历史数据和机器学习模型，不构成投资建议，请谨慎参考。</p>
                </div>
            </div>
        </div>
    </div>

    <footer class="bg-gray-800 text-white py-6 mt-12">
        <div class="container mx-auto px-4 text-center">
            <p>© 2023 股票价格预测系统 - 使用Flask和TensorFlow构建</p>
        </div>
    </footer>
</body>
</html>